package com.nontax.test.common.handler;

import com.nontax.test.common.domain.BaseResponse;
import com.nontax.test.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ResponseBody
    @ExceptionHandler(value = BusinessException.class)
    public BaseResponse javaExceptionHandler(BusinessException ex) {
        log.error("捕获到BusinessException异常",ex);
        return BaseResponse.error(StringUtils.isEmpty(ex.getMessage())?"未捕获到异常信息，请查看日志" : ex.getMessage());
    }
}
